package fun.carliels.doraemon.common.ocr;

import fun.carliels.doraemon.common.io.FileKit;
import fun.carliels.doraemon.common.random.RandomStrKit;
import net.sourceforge.tess4j.Tesseract;
import org.apache.commons.io.FileUtils;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.net.URI;
import java.net.URL;

/**
 * 验证码识别 tess4j
 * @author 残血拉二胡
 */
public class VerifyCodeOCR {

    public static final String ocr(String url) throws Exception{
        File file = FileKit.getNetUrlHttp(url, "jpg");
        if (file.exists()) {
            Tesseract instance = new Tesseract();
            instance.setDatapath("D:\\git\\doraemon\\common\\src\\main\\resources\\tessdata");
            instance.setLanguage("eng");
            return instance.doOCR(file);
        }
        return null;
    }

    public static void main(String[] args) throws Exception {
        String verifyId = RandomStrKit.genNumber(32);
        String url = "https://kxlabs.10086.cn/proxy_webbas/cap/login/createImg/" + verifyId;
        System.out.println(ocr(url));
    }
}
